package com.shaoshaohuo.app.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by Administrator on 2017/6/6.
 */

public class MyViewPagerAdapter extends PagerAdapter {

    private List<ImageView> picuture_data;
    private Context context;

    public MyViewPagerAdapter(Context context, List<ImageView> picuture_data) {
        this.picuture_data = picuture_data;
    }


    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    @Override
    public int getCount() {
        return picuture_data != null ? picuture_data.size() : 0;
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
        if (object instanceof View) {
            View view = (View) object;
            container.removeView(view);
        }
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        View ret = null;
        ret = picuture_data.get(position);
        container.addView(ret);
        return ret;
    }
}
